package com.hxzy.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author wzm
 * @create 2024-03-11 14:35
 * project_name:JavaWeb2401
 * @Description
 */
//拦截器入门
//@Component //将普通的类注入到ioc
public class FirstTestInterceptor implements HandlerInterceptor {
    //重写拦截器的方法 完成自定义功能


    //在控制器目标方法执行前执行  返回值 true 直接放行 false拦截不放行
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("pre....");
        return true;
    }

    //在控制器目标方法执行后执行
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle。。。。");
    }

    //Spring中控制器整合了页面，当页面视图完成渲染后 执行
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
       /* System.out.println("视图渲染");*/
    }
}
